<!DOCTYPE html>
<html>
<head>
  <script type="application/javascript">
    /* <![CDATA[ */
    var sessionFrame;
    var messageDiv;

    window.onload = function () {
      sessionFrame = document.getElementById('sessionFrame');
      sessionFrame.src = "http://localhost:8080/uaa/session?clientId=testClient&messageOrigin=" + encodeURIComponent(window.location.origin);
      messageDiv = document.getElementById('message');
    };

    window.addEventListener('message', function (e) {
      messageDiv.innerHTML = e.data;
    }, false);

    function sendNoUser() {
      sessionFrame.contentWindow.postMessage('testClient ~', '*');
    }

    function sendSameUser() {
      var userId = getUserId();
      sessionFrame.contentWindow.postMessage('testClient ' + userId, '*');
    }

    function sendDifferentUser() {
      sessionFrame.contentWindow.postMessage('testClient 5f74fee2-5736-4642-8fe7-5352cc357e5d', '*');
    }

    function sendWrongClient() {
      var userId = getUserId();
      sessionFrame.contentWindow.postMessage('wrongClient ' + userId, '*');
    }

    function getUserId() {
      if (!window.location.hash || window.location.hash === '' || window.location.hash === '#') return '~';
      else return window.location.hash.substring(1);
    }
    /* ]]> */
  </script>
</head>
<body>
<ul id="testLinks">
  <li><a href="javascript:void(0)" id="noUser" onclick="sendNoUser()">Send No User</a></li>
  <li><a href="javascript:void(0)" id="sameUser" onclick="sendSameUser()">Send Same User</a></li>
  <li><a href="javascript:void(0)" id="differentUser" onclick="sendDifferentUser()">Send Different User</a></li>
  <li><a href="javascript:void(0)" id="wrongClient" onclick="sendWrongClient()">Send Wrong Client</a></li>
</ul>
<br/>
<div id="message">
</div>
<iframe id="sessionFrame" src="about:blank" style="visibility: hidden"></iframe>
</body>
</html>
